import {
  createRouter,
  createWebHashHistory
} from 'vue-router'
import LoginView from '../views/LoginView.vue'
import DocUserView from '@/views/doctor/UserView.vue'
import MedUserView from '@/views/meditechnology/UserView.vue'
import PhaUserView from '@/views/pharmacy/UserView.vue'
import RegUserView from '@/views/registration/UserView.vue'
import PhaMainview from '@/views/pharmacy/MainView.vue'
import PhaDrugView from '@/views/pharmacy/DrugView.vue'
import PhaDispensingView from '@/views/pharmacy/DispensingView.vue'
import PhaRegressionView from '@/views/pharmacy/RegressionView.vue'
import DoctorIndex from '@/views/doctor/Index.vue'
import MedicalRecord from '@/views/doctor/MedicalRecord.vue'
import CheckList from '@/views/check/checkList.vue'
// 除了以上视图，其他视图的引入一律采用懒加载，写在component后面！

// 路由规则
const routes = [{
    path: "/",
    redirect: "/login",
  },
  {
    path: "/login",
    component: LoginView,
  },
  // 医生模块所有路由规则（不能超过该大括号）
  {
    path: '/doctor',
    component: DocUserView,
    redirect: '/doctor/index',
    children: [{
        path: 'index',
        component: DoctorIndex
      },
      {
        path: 'record',
        redirect: '/doctor/record/patientInfo',
        component: MedicalRecord,
        children: [{
            path: 'patientInfo',
            component: () => import('@/views/doctor/medicalRecord/PatientInfo.vue')
          },
          {
            path: 'inspection',
            component: () => import('@/views/doctor/medicalRecord/Inspection.vue')
          },
          {
            path: 'inspectionResult',
            component: () => import('@/views/doctor/medicalRecord/InspectionResult.vue')
          },
          {
            path: 'prescription',
            component: () => import('@/views/doctor/medicalRecord/Prescription.vue')
          },
        ]
      }
    ]
  },

  // 医技模块所有路由规则
  {
    path: '/checkIndex',
    component: CheckList,
  },

  // 药房模块所有路由规则
  {
    path: '/pharmacy',
    component: PhaUserView,
    redirect: '/pharmacy/main',
    children: [{
        path: 'main',
        component: PhaMainview,
      },
      {
        path: 'drug',
        component: PhaDrugView
      },
      {
        path: 'dispensing',
        component: PhaDispensingView
      },
      {
        path: 'regression',
        component: PhaRegressionView,
      }
    ],
  },

  // 挂号收费模块所有路由规则
  {
    path: '/registration',
    component: RegUserView,
  }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})

// router.beforeEach((to,from,next)=>{
//   const identify =JSON.parse(window.sessionStorage.getItem("userInfo"));
//   const token=window.sessionStorage.getItem("token")
//   console.log(token)
//   let toPath = to.path;
//   if (identify === null && toPath !== '/login'&&toPath !== '/register'&&toPath!='/') {
//     // 将用户重定向到登录页面
//     next({ path: '/login' });
//   }
//   else if(toPath.split('/')[1]!=from.path.split('/')[1]){
//     next(false)
//   }
//   else if(token==null||token==''){
//     next(false)
//   }
//   else{
//     next();
//   }
// })
export default router